<%@page import="java.util.List"%>
<%@page import="cn.edu.scau.Bean.Classes"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script type="text/javascript">
	function refresh(obj) {

		var url;
		switch (obj.id) {

		case "first":
			url = "http://localhost/Tables/class.do?type=first&now="
					+ new Date();
			break;
		case "pre":
			url = "http://localhost/Tables/class.do?type=pre&now=" + new Date();
			break;
		case "next":
			url = "http://localhost/Tables/class.do?type=next&now="
					+ new Date();
			break;

		case "last":
			url = "http://localhost/Tables/class.do?type=last&now="
					+ new Date();
			break;

		}

		//获得xmlHttpRequest ;
		var xmlRequest = new XMLHttpRequest();

		var method = "GET";

		//调用xmlHttpRequest的open方法
		xmlRequest.open(method, url);

		//调用xmlRequest的send方法

		xmlRequest.send(null);

		//添加statechange函数
		xmlRequest.onreadystatechange = function() {

			if (xmlRequest.readyState == 4) {

				if (xmlRequest.status == 200 || xmlRequest.status == 200) {

					var result = xmlRequest.responseText;
					obj = eval(result);
					var myobj = obj[0].classes;
					var table = document.getElementById("table");

					for (var i = 0; i < 5; i++) {

						for (var j = 0; j < 2; j += 2) {

							table.rows[i].cells[j].innerText = obj[0].classes[i].classId;

							table.rows[i].cells[j + 1].innerText = obj[0].classes[i].className;
						}
					}

				}
			}
		}

		//取消默认的事件
		return false;

	}

	function direct(obj) {

		
		window.location.href = "http://localhost/Tables/student.do?classId="
				+ obj.cells[0].innerText;

	}
</script>

</head>
<body>
	<h1 align="center">班级</h1>
	<%
		List<Classes> classes = (List<Classes>) session.getAttribute("classes");
	%>
	<table align="center" border="5" id="table">
		<%
			for (Classes classDemo : classes) {
		%>
		<tr onclick="direct(this)">
			<td><%=classDemo.getClassId()%></td>
			<td><%=classDemo.getClassName()%></td>
		</tr>
		<%
			}
		%>

	</table>
	<table align="center">
		<td><input type="button" value="首页" id="first"
			onclick="refresh(this)" /></td>
		<td><input type="button" value="上一页" id="pre"
			onclick="refresh(this)" /></td>
		<td><input type="button" value="下一页" id="next"
			onclick="refresh(this)" /></td>
		<td><input type="button" value="尾页" id="last"
			onclick="refresh(this)" /></td>
	</table>

</body>
</html>